package com.example.lppp.program;

import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONUtil;
import com.example.lppp.data.JsonRootBean;
import javafx.application.Platform;
import javafx.fxml.FXML;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;

public class HelloController {
    @FXML
    private Label myText;
    @FXML
    private TextField ipTxt;

    @FXML
    protected void onHelloButtonClick() {
        //起到一个Loading的效果
        myText.setText("Loading……");
       // String ipVal = ipTxt.getText();
        //异步机制
        Platform.runLater(() -> {
            String url = "https://qqlykm.cn/api/yan/gc.php";
            String result = HttpUtil.get(url);
            JsonRootBean ipData = JSONUtil.toBean(result, JsonRootBean.class);
            //System.out.println(ipData.getData().getIp());
            try {
                Thread.sleep(5000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            String outMsg="code：" + ipData.getMsg()+"\n";
            outMsg+="作者："+ipData.getData().getAuthor()+"\n";
            outMsg+="年份："+ipData.getData().getDynasty()+"\n";
            outMsg+="内容："+ipData.getData().getContent()+"\n";
            myText.setText(outMsg);
        });

    }
}